package com.lagou.xml;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
import org.junit.Test;

import java.util.List;

public class XPath {
    @Test
    public void testXPath() throws DocumentException {
        SAXReader saxReader=new SAXReader();

        Document document = saxReader.read("E:\\Java\\java train\\jdbc_work\\jdbc_task05\\src\\com\\lagou\\xml\\books.xml");

        //1.找出book id=01的图书的所有内容
        List<Node> list = document.selectNodes("/books/book[@id='01']//*");
        for (Node node1:list){
            System.out.println(node1.getName()+":"+node1.getText());
        }
        System.out.println("_____________________________________________________");


        //2.找出book id=02的图书的所有内容
        List<Node> list1 = document.selectNodes("/books/book[@id='02']//*");
        for (Node node1:list1){
            System.out.println(node1.getName()+":"+node1.getText());
        }
        System.out.println("_____________________________________________________");


        //3.找出book id=01的图书的所有内容
        List<Node> list2 = document.selectNodes("/books/book[@id='03']//*");
        for (Node node1:list2){
            System.out.println(node1.getName()+":"+node1.getText());
        }
    }
}
